<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>table模块快速使用</title>
    <link rel="stylesheet" href="/layui/lib/layui-v2.5.5/css/layui.css" media="all">

    <link rel="stylesheet" href="/js/layui_exts/tree_themes/auth-skin-default.css">

</head>
<body>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">角色名</label>
        <div class="layui-input-inline">
            <input type="text" name="role_name"value="{{ $rows->role_name }}" required lay-verify="required"  class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">选择权限</label>
        <div class="layui-input-block">
            <div id="LAY-auth-tree-index"></div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" type="submit" lay-submit lay-filter="LAY-auth-tree-submit">提交</button>
            <button class="layui-btn layui-btn-primary" type="reset">重置</button>
        </div>
    </div>
</form>
<script src="/layui/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    //Demo
    layui.config({
        base: '/js/layui_exts/',
    }).extend({
        authtree: 'authtree',
    });
    layui.use(['jquery', 'authtree', 'form', 'layer'], function(){
        var $ = layui.jquery;
        var authtree = layui.authtree;
        var form = layui.form;
        var layer = layui.layer;
        // 初始化
        $.ajax({
            url: '/admin/role_edit_json/'+"{{ $rows->id }}",
            dataType: 'json',
            success: function(data){
                // 渲染时传入渲染目标ID，树形结构数据（具体结构看样例，checked表示默认选中），以及input表单的名字
                authtree.render('#LAY-auth-tree-index', data.data.trees, {
                    inputname: 'node_id[]'
                    ,layfilter: 'lay-check-auth'
                    ,nameKey: 'name' //名称，名字根据json可改
                    ,valueKey: 'id' //value值，名字根据json可改
                    ,openall: true
                    ,checkedKey:'checked'
                    ,'theme': 'auth-skin-default'
                    ,'themePath': '/js/layui_exts/tree_themes/'
                    ,autowidth: true
                });
            }
        });
        form.on('submit(LAY-auth-tree-submit)', function(obj){
            var authids = authtree.getChecked('#LAY-auth-tree-index');
            var result=obj.field;
            var id="{{ $rows->id }}";
            console.log(result);
            $.ajax({
                url: '/admin/role_update',
                type:'post',
                dataType: 'json',
                data: {'_token':'{{ csrf_token() }}',result,authids,id},
                success: function(res){
                    if(res){
                        parent.layer.closeAll();
                        parent.location.reload();
                    }
                }
            });
            return false;
        });
    });

</script>
</body>
</html>